package com.cans.factory.simple;

import java.util.Objects;

/**
 * 工厂模式 - 简单工厂
 */
public class FactoryImpl {

    /**
     * 获取实现
     * @param name
     * @return
     */
    public Phone getInstanceByName(String name){
        if(Objects.equals("iphone",name)){
            return new IPhone();
        }else  if(Objects.equals("xiaomi",name)){
            return new MiPhone();
        }
        return null;
    }


    public static void main(String[] args) {
        String iphone = "iphone";
        String xiaomi = "xiaomi";
        FactoryImpl factory = new FactoryImpl();
        Phone iphoneInstance = factory.getInstanceByName(iphone);
        System.out.println(iphoneInstance.information());
        Phone xiaomiInstance = factory.getInstanceByName(xiaomi);
        System.out.println(xiaomiInstance.information());
    }
}
